/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package music.types;

import MidiGui.MusicFonts;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Toolkit;
import music.Note;
import music.SpacingOptions;
import music.global.CharacterMap;

/**
 *
 * @author TJ
 */
public enum ClefType{
    BASS('G',43,(char)0xf03f,3),TREBLE('E',64,(char)0xf026,1),TENOR_CLEF('D',50,(char)0xf042,3),PERCUSSION('E',64,(char)0xf02f,1),BARITONE_CLEF('D',43,(char)0xf042,2);
    private char baselineNote;
    private char clefSymbol;
    private int baselineNoteVal;
    private int off;
    private ClefType(char c, int v, char symbol,int lineoffset){this.baselineNote=c;
    this.baselineNoteVal=v;
    clefSymbol=symbol;
    off=lineoffset;
    }
    public int getWidth(SpacingOptions s){
        return CharacterMap.getWidth(clefSymbol, s.getRenderFont());
    }
    public int getLedgerLines(MidiNote note) {
        int linesAbove=Interval.getScaleDegreeBetween(new MidiNote(baselineNoteVal,""+baselineNote), note);
        if(linesAbove>=8) {
            return (linesAbove-8)/2;
        }else if(linesAbove<0) {return linesAbove/2;}
        return 0;
    }
    public boolean renderUpsideDown(Note note) {
        int net=0;
        for(MidiNote n : note.getNotes()) {
            net+=Interval.getScaleDegreeBetween(new MidiNote(baselineNoteVal,""+baselineNote), n);
        }
        return (double)net/note.getNotes().size()>=4;
    }
    public int getRenderY(SpacingOptions s, int bottomLine,MidiNote note){
        if(note!=null) {
            return bottomLine-Interval.getScaleDegreeBetween(new MidiNote(baselineNoteVal,""+baselineNote), note)*(s.getLineSpacing()/2)+(s.getLineSpacing()/2);
        }
        return bottomLine-2*s.getLineSpacing()+s.getLineSpacing()/2;
    }
    public int render(Graphics g,int baseLine, SpacingOptions s,int x){
            Font font=MusicFonts.getFont("OpusRegular").deriveFont((float)(s.getLineSpacing()*4+1));
             g.setFont(font);
             g.drawString(""+((char)clefSymbol), x,baseLine-s.getLineSpacing()*off);
             FontMetrics m=Toolkit.getDefaultToolkit().getFontMetrics(font);
             return m.charWidth((char)clefSymbol);
    }
    public char getBaseLine() {
        return this.baselineNote;
    }
    public int getBaseLineVal() {
        return this.baselineNoteVal;
    }
}
